package com.zyx.pulsardemo.basic.readers;

import org.apache.pulsar.client.api.MessageId;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.api.Reader;

/**
 * @author Yaxi.Zhang
 * @since 2021/9/30 18:03
 * desc: 从最迟消息开始读取
 * reference: https://github.com/david-streamlio/pulsar-in-action
 */
public class LatestReader extends PulsarReaderDemoBase {

	public static void main(String[] args) throws Exception {
		LatestReader lr = new LatestReader();
		lr.startProducer();
		lr.startReader();
	}

	@Override
	protected Reader<byte[]> getReader() {
		try {
			return getClient().newReader()
						.topic(topic)
						.readerName(readerName)
						.startMessageId(MessageId.latest)
						.create();
		} catch (PulsarClientException e) {
			return null;
		}
	}

}
